package election.platform;

import election.api.Get;
import election.api.Put;


public class BlockQueue extends MyQueue
{
    @Override
    public void put(Object obj)
    {
        synchronized(queue) {
            System.out.println("Add data to queue");
            queue.add(obj);
            queue.notify();
        }
    }

    @Override
    public Object get() throws Exception
    {
        synchronized(queue) {
            if (queue.isEmpty()) {
                System.out.print("wait... ");
                queue.wait();
                System.out.println("resume");
            }
            return queue.poll();
        }
    }
}